package com.bdqn.tour.servlet.Hzy;

import com.alibaba.fastjson.JSON;
import com.bdqn.tour.service.impl.HzyTravelersServiceImpl;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/setDefaultTraveler")
public class SetDefaultTravelerServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=UTF-8");
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        PrintWriter out = resp.getWriter();


        int id = Integer.parseInt(req.getParameter("id"));
        boolean success = new HzyTravelersServiceImpl().setDefaultTraveler(id);

        Map<String, Object> result = new HashMap<>();
        result.put("success", success);
        result.put("message", success ? "设置成功" : "设置失败");

        String json = JSON.toJSONString(result);
        out.print(json);
        out.close();
    }
}
